'use strict';

define(['controllers', 'codemirror', 'codemirror-xml', 'codemirror-javascript', '../service/deleteService'], function (controllers, CodeMirror) {
    controllers.collection.register('DeleteController', ['$scope', '$routeParams', 'DeleteService', function ($scope, $routeParams, deleteService) {
        $scope.collectionId = $routeParams.id;
        $scope.init = function () {
            $scope.delete_query = '';
            $scope.delete_commit = true;

            $scope.removing = false;

            setTimeout(function () {
                $scope.result_editor = CodeMirror.fromTextArea(document.getElementById("result_editor"), {
                    mode: "application/json",
                    styleActiveLine: true,
                    lineNumbers: true,
                    lineWrapping: true
                });
            }, 10);
        };

        $scope.remove = function () {
            $scope.removing = true;
            deleteService.remove($scope.collectionId, {
                query: $scope.delete_query,
                commit: $scope.delete_commit
            }, function (data) {
                $scope.result_editor.setValue(data);
                $scope.removing = false;
            });
        };

        $scope.init();
    }]);
});